package com.zhixing.user.controller;

import com.zhixing.common.annotation.Driver;
import com.zhixing.common.utils.Res;
import com.zhixing.user.domain.vo.DriverLicenseOcrVO;
import com.zhixing.user.domain.vo.IdCardOcrVO;
import com.zhixing.user.service.CloudService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 腾讯云接口
 */
@Slf4j
@RestController
@RequestMapping("/cloud")
@RequiredArgsConstructor
public class CloudController {

    private final CloudService cloudService;

    /**
     * 上传图片
     * @param file 图片
     * @return 图片地址
     */
    @PostMapping("/upload")
    public Res<String> upload(@RequestPart("file") MultipartFile file) {
        log.info("用户服务调用，上传图片");
        return Res.ok(cloudService.upload(file, "avatar"));
    }

    /**
     * 身份证识别
     * @param file 图片
     * @return 识别结果
     */
    @Driver
    @PostMapping("/idCardOcr")
    public Res<IdCardOcrVO> idCardOcr(@RequestPart("file") MultipartFile file) {
        log.info("用户服务调用，身份证识别");
        return Res.ok(cloudService.idCardOcr(file));
    }

    /**
     * 驾驶证识别
     * @param file 图片
     * @return 识别结果
     */
    @Driver
    @PostMapping("/driverLicenseOcr")
    public Res<DriverLicenseOcrVO> driverLicenseOcr(@RequestPart("file") MultipartFile file) {
        log.info("用户服务调用，驾驶证识别");
        return Res.ok(cloudService.driverLicenseOcr(file));
    }
}
